export default class ScaleTw extends Laya.Script{
    /** @prop {name:twsacle,tips:"ss",type:number,default:0.8}*/
    public twScale:number=0.8;
    /** @prop {name:step,tips:"step",type:number,default:0.01}*/
    public step:number=0.01;
      /** @prop {name:isAutoRun,tips:"isAutoRun",type:boolean,default:false}*/
    public isAutoRun:boolean=false;
    private currScle:number=1;
    private mminScale:number;
    private mmaxScale:number;
    private mIsRun:boolean;

    onEnable(){
        if(this.isAutoRun){
            this.isRun=true;
        }
    }
    onUpdate(){
        if(this.mIsRun){
            this.currScle += this.step;
            if(this.currScle<=this.mminScale || this.currScle>=this.mmaxScale)this.step *= -1;
            this.updateScale();
        }
    }

    private updateScale(){
        this.owner["scaleX"]=this.owner["scaleY"]=this.currScle;
    }

    public set isRun(_vale:boolean){
        this.mIsRun=_vale;
        this.currScle=1;
        this.step=Math.abs(this.step);
        if(_vale){
            this.mminScale=Math.min(this.twScale,1);
            this.mmaxScale=Math.max(this.twScale,1);
            if(this.currScle>this.twScale)this.step *= -1;
        }
        this.updateScale();
    }

    public get isRun(){
        return this.mIsRun;
    }
}